﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MetadataBasedConfigArch.Framework.Configurable;
using MetadataBasedConfigArch.Framework.Processor;

namespace MetadataBasedConfigArch.Framework
{
    public static class Helper
    {
        #region Static Ctor

        static Helper()
        {
            ConfigurableContentMapping = new Dictionary<Type, string>();
            ConfigurableContentMapping.Add(typeof(ITableConfigurable), Constants.ConfigTypeName_Table);
            ConfigurableContentMapping.Add(typeof(IUIConfigurable), Constants.ConfigTypeName_UI);
            ConfigurableContentMapping.Add(typeof(IWorkFlowConfigurable), Constants.ConfigTypeName_WorkFlow);
            ConfigurableContentMapping.Add(typeof(IFunctionConfigurable), Constants.ConfigTypeName_Function);            
        }

        #endregion

        #region Static Fields

        public static readonly Dictionary<Type, String> ConfigurableContentMapping = null;

        #endregion

        #region Config Type Static Methods

        public static String GetConfigurableConfigTypeName<T>()
            where T : IConfigurable
        {
            return GetConfigurableConfigTypeName(typeof(T));
        }

        public static String GetConfigurableConfigTypeName(Type configurableType)
        {
            if (typeof(IConfigurable).IsAssignableFrom(configurableType))
            { 
                foreach (var type in ConfigurableContentMapping.Keys)
                {
                    if (type.IsAssignableFrom(configurableType))
                    {
                        return ConfigurableContentMapping[type];
                    }
                }
            }
            return String.Empty;
        }

        #endregion

    }
}
